var app = getApp()
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid:"",
    title:"",
    text:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      createtime: util.formatTime(new Date())
    });
    console.log(this.data.createtime)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  formSubmit: function(e){
    var that = this
    console.log("111");
    console.log(e.detail.value);
    if (e.detail.value.text == "") {
      wx.showToast({
        title: '手记怎么会没有内容呢~',
        icon: "none"
      })
      return false;
    } 
    if (e.detail.value.title == "") {
      wx.showToast({
        title: '手记怎么会没有标题呢~',
        icon: "none"
      })
      return false;
    } 
    wx.request({
      url: `${app.globalData.apiurl}api/index/addNote`,
      method: "POST",
      data: { 
        uid: app.globalData.userInfo.uid,
        title: e.detail.value.title,
        text: e.detail.value.text
      },

      success: function (res) {
        console.log(that.data.text);
        wx.showToast({
          title: '本次随手记已装袋啦~',
          icon: "none"
        })
        setTimeout(function () {
          wx.switchTab({
            url: '/pages/note/note',
          })
        }, 1000)
      }
    })
  },
  
})